package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlw.hr_man.service.DaleteDeptService;
import com.hlw.hr_man.serviceImpl.DaleteDeptServiceImpl;

public class DaleteDeptController extends HttpServlet{
	DaleteDeptService dds = new DaleteDeptServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		
		PrintWriter pw = resp.getWriter();
		String dept_id[] = req.getParameterValues("dept_id[]");
		int flag = 1;
		for(int i =0;i<dept_id.length;i++){
		     if(dds.selectEmployee(Integer.parseInt(dept_id[i]))==1){
		    	 flag = 2;
		    	 break;
		     }else {
		    	 if(dds.daleteDept(Integer.parseInt(dept_id[i]))!=1){
		    		 flag = 1;
		    	 }
		     }
		}
		pw.write(String.valueOf(flag));
		
	}

}
